import tool from 'src/util/tool'
import util from '_util/index';
import _ from 'lodash'

const state = {
    auth: null,
    auth_ctls:null
};
const getters = {
    auth_ctls(){

    }
}
const mutations = {
    setAuth(state, auth){
        state.auth = auth

    },
    set_auth_ctls(state){
        let menu_auths= state.auth.menu_auths;
        if(!menu_auths) {
            return null;
        }
        let auth_ctls = [];
        menu_auths.forEach(menu_auth => {
            let rs=menu_auth.menu_group;
            if(rs)
                util.forEach(rs,(ind,item) => {
                    item && auth_ctls.push(JSON.parse(item.attr_group_str));
                });
        });

        auth_ctls=_.reduce(auth_ctls, function(result, item) {
            result = _.concat(result,_.flattenDeep(item));
            return _.uniq(result);
        }, []).sort((a,b)=> {
            return a - b;
        });
        // tool.cl('auth_ctls:', auth_ctls);
        state.auth_ctls = auth_ctls;
    }
}
const actions = {}

export default{
    namespaced: true,
  state,
  getters,
  actions,
  mutations
}
